package com.lagou.edu.controller;

import com.lagou.edu.dao.ResumeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private ResumeDao resumeDao;

    @RequestMapping("login")
    public ModelAndView login(@RequestParam String account, String password, HttpSession httpSession) {

        if (httpSession.getAttribute("login") != null || "admin".equals(account) && "admin".equals(password)) {
            httpSession.setAttribute("login", true);
            ModelAndView mv = new ModelAndView("resume.jsp");
            mv.addObject("list", resumeDao.findAll());
            return mv;
        }
        ModelAndView mv = new ModelAndView("index.jsp");
        mv.addObject("message", "密码错误");
        return mv;
    }
}
